﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;


namespace NJL.Web.Controls
{
    public partial class WUCIndexTopNews : BaseUserControl
    {
        protected string FROM_URL = "";

        private readonly BLL.NJL_SYS_NEWS bll = new BLL.NJL_SYS_NEWS();
        private readonly BLL.NJL_CS_TAG bllTag = new BLL.NJL_CS_TAG();
        private readonly BLL.NJL_NEWS bllNews = new BLL.NJL_NEWS();
        private readonly BLL.NJL_COMPANY bllCompany = new BLL.NJL_COMPANY();
        private readonly BLL.NJL_ATTRACTION bllAttraction = new BLL.NJL_ATTRACTION();
        private readonly BLL.NJL_CS_AREA bllArea = new BLL.NJL_CS_AREA();
        private readonly BLL.NJL_SYS_ANNOUNCEMENT bllNJL_SYS_ANNOUNCEMENT = new BLL.NJL_SYS_ANNOUNCEMENT();
        private readonly BLL.NJL_USER bllUser = new BLL.NJL_USER();
        private readonly BLL.NJL_LOCAL_COLOR bllLocalColor = new BLL.NJL_LOCAL_COLOR();
        BLL.NJL_ACTIVE bllActive = new BLL.NJL_ACTIVE();
        protected IList<Model.NJL_SYS_NEWS> LIST_LEFT;
        protected IList<Model.NJL_SYS_NEWS> LIST_FLASH;
        protected IList<Model.NJL_CS_TAG> LIST_TAG;
        protected IList<Model.NJL_NEWS> LIST_NEWS;
        protected IList<Model.NJL_COMPANY> LIST_COMPANY;
        protected IList<Model.NJL_ATTRACTION> LIST_ATTRACTION;

        protected int PROVINCE_COUNT = 0;
        protected int CITY_COUNT = 0;
        protected int COMPANY_COUNT = 0;
        protected int USER_COUNT = 0;
        protected int LOCAL_COLOR_COUNT = 0;
        protected int ATTRACTION_COUNT = 0;

        protected void Page_Load(object sender, EventArgs e)
        {
            LoadData();
            if (!IsPostBack)
            {
                bind();
            }
        }

        private void LoadData()
        {
            LIST_LEFT = bll.GetModelList(6, " NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' AND IS_PUBLISH=1 AND IS_INDEX=1 AND TYPE_CODE in ('30','31','32','33','34','35','36','37','38','39','40') ", "SORT DESC,PUBLISH_DATE_TIME DESC");
            LIST_FLASH = bll.GetModelList(10, " NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' AND IS_PUBLISH=1 AND IS_INDEX=1 AND TYPE_CODE='11' ", "SORT DESC,PUBLISH_DATE_TIME DESC");

            LIST_NEWS = bllNews.GetModelList(3, " NJL_SYS_BASE_ID='" + WEBSITE_CODE + "'", " CREATE_DATE_TIME DESC");
            LIST_COMPANY = bllCompany.GetModelList(3, " NJL_COMPANY.NJL_SYS_BASE_ID='" + WEBSITE_CODE + "'", " NJL_COMPANY.SORT DESC,NJL_COMPANY.CREATE_DATE_TIME DESC");

            if (WEBSITE_FOCUS_CITY_CODE != "")
            {
                LIST_TAG = bllTag.GetModelList(10, " NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' and TAG_TYPE='5' and AREA_CODE='" + WEBSITE_FOCUS_CITY_CODE + "'", "SEARCH_COUNT desc,USED_COUNT DESC");
                LIST_ATTRACTION = bllAttraction.GetModelList(6, " NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' AND AREA_CODE='" + WEBSITE_FOCUS_CITY_CODE + "'", "SORT DESC,CREATE_DATE_TIME DESC");
            }
            else
            {
                LIST_TAG = bllTag.GetModelList(10, " NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' and TAG_TYPE='5' ", "SEARCH_COUNT desc,USED_COUNT DESC");
                LIST_ATTRACTION = bllAttraction.GetModelList(6, " NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' ", "SORT DESC,CREATE_DATE_TIME DESC");
            }

            //PROVINCE_COUNT = bllArea.GetModelList(" deep=1 ").Count;
            CITY_COUNT = bllArea.GetModelList(" deep=2 and AREA_CODE like '" + WEBSITE_CODE.Substring(0, 2) + "%' ").Count;
            COMPANY_COUNT = bllCompany.GetListCount(" NJL_COMPANY.NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' ");
            //USER_COUNT = bllUser.GetModelList(" NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' ").Count;
            USER_COUNT = bllUser.GetModelList(" ").Count;
            LOCAL_COLOR_COUNT = bllLocalColor.GetModelList(" NJL_LOCAL_COLOR.NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' ").Count;
            ATTRACTION_COUNT = bllAttraction.GetModelList(" NJL_ATTRACTION.NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' ").Count;


            if (Request.QueryString["url"] != null && Request.QueryString["url"] != "")
            {
                FROM_URL = Server.UrlEncode(Server.UrlDecode(Request.QueryString["url"]));
            }
            else
            {
                FROM_URL = Server.UrlEncode(Request.RawUrl);
            }
            #region 活动列表数据
            DataSet ds = bllActive.GetList(8, "NJL_COMPANY_ID in(SELECT ID FROM NJL_COMPANY WHERE NJL_SYS_BASE_ID='" + WEBSITE_CODE + "') and IS_PUBLISH=1", "SORT desc,CREATE_DATE_TIME desc");
            rptActive.DataSource = ds;
            rptActive.DataBind();
            #endregion

        }
        public void bind()
        { 
            //DataSet ds = bllNJL_SYS_ANNOUNCEMENT.GetList(3, "", "CREATE_DATE_TIME desc");
            //rptNotice.DataSource = ds;
            //rptNotice.DataBind();
        }

    }
}